package com.ruoyi.web.controller.mobile;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysDictData;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.frontierEvent.bo.TEventAddBo;
import com.ruoyi.system.frontierEvent.vo.TEventVo;
import com.ruoyi.system.mobile.bo.TEventEditBo;
import com.ruoyi.system.mobile.bo.TEventQueryBo;
import com.ruoyi.system.frontierEvent.service.ITEventService;
import com.ruoyi.system.mobile.service.EventService;
import com.ruoyi.system.mobile.vo.EventVo;
import com.ruoyi.system.service.ISysDictDataService;
import com.ruoyi.system.service.ISysDictTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * App案件信息Controller
 * 
 * @author ruoyi
 * @date 2021-05-19
 */
@Api(value = "App案件信息控制器", tags = {"案件信息管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/mobile/event")
public class EventController extends BaseController {

    private final EventService iTEventService;

    private final ITEventService itEventService;

    /**
     * 查询案件信息列表
     */
    @ApiOperation("查询案件信息列表")
    @GetMapping("/list")
    public TableDataInfo<EventVo> list(TEventQueryBo bo) {
        startPage();
        List<EventVo> list = iTEventService.queryList(bo);
        return getDataTable(list);
    }

    /**
     * 导出案件信息列表
     */
    @ApiOperation("导出案件信息列表")
    @Log(title = "案件信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<EventVo> export(TEventQueryBo bo) {
        List<EventVo> list = iTEventService.queryList(bo);
        ExcelUtil<EventVo> util = new ExcelUtil<EventVo>(EventVo.class);
        return util.exportExcel(list, "案件信息");
    }

    /**
     * 获取案件信息详细信息
     */
    @ApiOperation("获取案件信息详细信息")
    @GetMapping("/{id}")
    public AjaxResult<EventVo> getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iTEventService.queryById(id));
    }

    /**
     * 新增案件信息
     */
    @ApiOperation("新增案件信息")
    @Log(title = "案件信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult<Void> add(@RequestBody TEventAddBo bo) {
        return toAjax(itEventService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改案件信息
     */
    @ApiOperation("修改案件信息")
    @Log(title = "案件信息", businessType = BusinessType.UPDATE)
    @PutMapping("/update")
    public AjaxResult<Void> edit(@RequestBody TEventEditBo bo) {
        return toAjax(iTEventService.updateByEditBo(bo) ? 1 : 0);
    }

    @Autowired
    private ISysDictDataService dictDataService;



    @GetMapping("/source")
    public TableDataInfo list(SysDictData dictData)
    {
        startPage();
        List<SysDictData> list = dictDataService.selectDictDataList(dictData);
        return getDataTable(list);
    }
}
